﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Scripting;
using Microsoft.Linq.Expressions;
using Microsoft.Scripting.Runtime;

namespace JavascriptEngine.Runtime
{
    internal class JavascriptCode : ScriptCode
    {
        private Func<Scope, LanguageContext, object> _func;

        public JavascriptCode(Func<Scope, LanguageContext, object> func, SourceUnit sourceUnit)
            : base(sourceUnit)
        {
            _func = func;
        }

        public override object Run()
        {
            return _func(new Scope(), SourceUnit.LanguageContext);
        }

        public override object Run(Scope scope)
        {
            return _func(scope, SourceUnit.LanguageContext);
        }
    }
}
